/**
 * 字典管理配置文件
 */
import { h } from 'vue'
import { ElTag } from 'element-plus'

/**
 * 搜索条件配置
 */
export const searchConfig = [
  {
    field: 'name',
    label: '字典名称',
    component: 'Input',
    placeholder: '请输入字典名称',
    defaultValue: '',
  },
  {
    field: 'code',
    label: '字典编码',
    component: 'Input',
    placeholder: '请输入字典编码',
    defaultValue: '',
  },
  {
    field: 'status',
    label: '状态',
    component: 'Select',
    placeholder: '请选择状态',
    defaultValue: '',
    options: [
      { label: '启用', value: '1' },
      { label: '禁用', value: '0' },
    ],
  },
]

/**
 * 表格列配置
 */
export const tableConfig = [
  {
    type: 'selection',
    width: 55,
    fixed: 'left',
  },
  {
    type: 'index',
    width: 55,
    label: '序号',
  },
  {
    prop: 'name',
    label: '字典名称',
    minWidth: 120,
  },
  {
    prop: 'code',
    label: '字典编码',
    minWidth: 120,
  },
  {
    prop: 'description',
    label: '字典描述',
    minWidth: 180,
    showOverflowTooltip: true,
  },
  {
    prop: 'sort',
    label: '排序',
    minWidth: 80,
    sortable: true,
  },
  {
    prop: 'status',
    label: '状态',
    minWidth: 100,
    render: (row) =>
      h(
        ElTag,
        {
          type: row.status === '1' ? 'success' : 'danger',
        },
        () => (row.status === '1' ? '启用' : '禁用'),
      ),
  },
  {
    prop: 'createTime',
    label: '创建时间',
    minWidth: 180,
    render: (row) => row.createTime?.split(' ')[0] || '-',
  },
]
